package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.ZdrWlISTbean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/5/10.
 */

public class ZdrwListAdapter extends RecyclerView.Adapter<
        ZdrwListAdapter.Holder> {
    List<ZdrWlISTbean> zdrWlISTbeans;
    Context context;
    ZdrwClickListener clickListener;

    public void setZdrWlISTbeans(List<ZdrWlISTbean> zdrWlISTbeans,ZdrwClickListener clickListener) {
        this.zdrWlISTbeans = zdrWlISTbeans;
        this.clickListener = clickListener;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context)
                .inflate(R.layout.item_zdrw, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
            holder.tvName1.setText(zdrWlISTbeans.get(position).getXNAME());
            holder.tvName2.setText(zdrWlISTbeans.get(position).getFORGNAME());
            holder.tvName3.setText(zdrWlISTbeans.get(position).getT_Content());
            holder.tvName4.setText(zdrWlISTbeans.get(position).getT_ZRCS());
            holder.xqLl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickListener.click(zdrWlISTbeans.get(position));
                }
            });
    }

    @Override
    public int getItemCount() {
        if (zdrWlISTbeans == null){
            return 0;
        }else {
            return zdrWlISTbeans.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_name1)
        TextView tvName1;
        @Bind(R.id.tv_name2)
        TextView tvName2;
        @Bind(R.id.tv_name3)
        TextView tvName3;
        @Bind(R.id.tv_name4)
        TextView tvName4;
        @Bind(R.id.xq_ll)
        LinearLayout xqLl;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface ZdrwClickListener{
        void click(ZdrWlISTbean zdrWlISTbean);
    }

}
